<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let arr = [2, 1, 1, 9, 1, 3, 1, 4, 5, 1, 1]
      function getSum(nums) {
        let sum = 0
        let max = 0
        for (let i = 0; i < nums.length; i++) {
          let num = max
          max = Math.max(max, sum + nums[i])
          sum = num
        }
        return max
      }
      console.log(getSum(arr))
    </script>
  </body>
</html>
